#include<bits/stdc++.h>
using namespace std;
// #define int long long
int n,m;
string str;
int up[3005][3005],du[3004][3005],a[3005][3005],s[3005][3005],sum[3005];
int lans[3005][3005],rans[3005][3005],lp[3005],rp[3005];
long long ans;
void solve(int l,int r,int L,int R){
	if(l==r||L==R)return;
	int len1=r-l+1,len2=R-L+1,mid;
	if(len2>len1){
		mid=(L+R)>>1;
		solve(l,r,L,mid);solve(l,r,mid+1,R);
		for(int i=l;i<=r;i++){
			for(int j=L;j<=R;j++){
				s[i-l+1][j-L+1]=a[i][j];
			}
		}
	}else{
		mid=(l+r)>>1;
		solve(l,mid,L,R);solve(mid+1,r,L,R);
		for(int i=l;i<=r;i++){
			for(int j=L;j<=R;j++){
				s[j-L+1][i-l+1]=a[i][j];
			}
		}swap(len1,len2);
	}
	long long theans=0;mid=(1+len2)>>1;
	for(int j=1;j<=len2;j++){
		for(int i=1;i<=len1;i++){
			if(s[i][j]==s[i-1][j])up[i][j]=up[i-1][j]+1;
			else up[i][j]=1;
		}
		for(int i=len1;i>=1;i--){
			if(s[i][j]==s[i+1][j])du[i][j]=du[i+1][j]+1;
			else du[i][j]=1;
		}
	}
	for(int i=1;i<=len1;i++){
		for(int j=mid;j>=1;j--){
			if(j!=mid&&s[i][j]!=s[i][j+1])break;
			lp[i]=j;
		}
	}

	for(int i=1;i<=len1;i++){
		if(s[i][mid]!=s[i][mid+1])continue;
		for(int j=mid;j>=lp[i];j--){
			int l=i-up[i][j]+1,r=i+du[i][j]-1;
			sum[l]++;sum[r+1]--;
		}
		for(int j=1;j<=len1;j++)sum[j]+=sum[j-1];
		for(int j=1;j<=len1;j++){
			if(s[j][mid]!=s[j][mid+1])continue;
			if(s[i][mid]!=s[j][mid])continue;
			if(i==j)continue;
			if(lp[i]>lp[j]||(lp[i]==lp[j]&&i<j)){
				lans[min(i,j)][max(i,j)]=sum[j];
			}
		}
		for(int j=1;j<=len1+1;j++)sum[j]=0;
	}
	// cout<<"\n";
	for(int i=1;i<=len1;i++)lp[i]=0;
	for(int i=1;i<=len1;i++){
		for(int j=mid+1;j<=len2;j++){
			if(j!=mid+1&&s[i][j]!=s[i][j-1])break;
			lp[i]=j;
		}
	}
	for(int i=1;i<=len1;i++){
		if(s[i][mid]!=s[i][mid+1])continue;
		for(int j=mid+1;j<=lp[i];j++){
			int l=i-up[i][j]+1,r=i+du[i][j]-1;
			sum[l]++;sum[r+1]--;
		}
		for(int j=1;j<=len1;j++)sum[j]+=sum[j-1];
		for(int j=1;j<=len1;j++){
			if(s[j][mid]!=s[j][mid+1])continue;
			if(s[i][mid+1]!=s[j][mid+1])continue;
			if(i==j)continue;
			if(lp[i]<lp[j]||(lp[i]==lp[j]&&i<j)){
				ans+=1ll*lans[min(i,j)][max(i,j)]*sum[j];
			}
		}
		for(int j=1;j<=len1+1;j++)sum[j]=0;
	}
	for(int i=1;i<=len1;i++){
		for(int j=1;j<=len1;j++)lans[i][j]=0;
		for(int j=1;j<=len2;j++){
			s[i][j]=up[i][j]=du[i][j]=0;
		}
	}
}
signed main(){
	freopen("star.in","r",stdin);
	freopen("star.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	int tlh;
	tlh=1;
	tlh=2;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>str;str=" "+str;
		for(int j=1;j<=m;j++){
			a[i][j]=str[j]-'a'+1;
		}
	}
	solve(1,n,1,m);
	cout<<ans<<"\n";
	return 0;
}